<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
    <%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
       <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<!doctype html>
<html>
<head>
<jsp:include page="/common/commonCss.jsp"/>
<jsp:include page="/common/commonJs.jsp"/>
<title>嘉童游乐中心-新增采购订单清单</title>

<SCRIPT type="text/javascript">
	var pkPurordId ='${pkPurordId}';
	$(document).ready(function(){
		if('${oldSuppLyId}'!=""){
			$("#selectScmSupid").val('${oldSuppLyId}');
			refreshSelect();
		}
		
	}); 
	function selectSupId(oid){// 触发供应商 下拉框 onchange 事件
		 var value =$("#selectScmSupid").val();
		 if(value ==""){
			 alertWarning("请选择供应商。");
		 }else{ 
			 window.location.href='${basePath}scmInvocing/scmPurOrder/invoOrderNewGundong.shtml?type=add&pkPurordId=${pkPurordId}&supplyId='+value;
		 }
	}
	
	function saveSupRrd(saveType,purStatus){
		 $.messager.confirm('提示', '确认要提交吗?', function(r) {
				if(r){
					var isOK = true;
					$("#itemsTable tr").each(function(){
					if($(this).find("td:eq(7)").find("input").val() > 0)
							{
								isOK=false;
							}
					});
					if(isOK)
						{
						alertWarning("请至少填写一项采购数量！");
						return;
						}
					
					var supplyIds=document.getElementById("selectScmSupid").value;
					if(supplyIds==""){
						 alertWarning("请选择供应商！");
						 return;
					} 
					var msgText="保存";
					if(purStatus =="2"){
						msgText="提交";
					}
					 var pkPurordId ='${pkPurordId}';
					 var url ='${basePath }scmInvocing/scmPurOrder/savePurOrderPrdBatch.shtml?saveType='+saveType+'&fkPurordId='+pkPurordId+'&scmSupIds='+supplyIds+'&purStatus='+purStatus;
						$.ajax({
							   url: url,
							   type: 'POST',
							   data:$("#supPrdForm").serialize(),//序列化表单里所有的内容
							      async:false, 
							   success:function(msg){
									if (msg != "1") {
										if(msg=="2"){
											alertInfo("供应商不存在，不能提交审批。");
										}else{
										 alertInfo(msgText+"失败！");
										}
									}else{
										//alertInfo(msgText+"成功！");
										setTimeout(fanhui(), 10000 );
										
									}
							   },
								error : function(XMLHttpRequest) {
									ajaxError(XMLHttpRequest);
								}
						});
				}
		 });
		
	}
	
	 
	function fanhui(){
		window.location.href='${basePath }scmInvocing/scmPurOrder/findInvoPurOrder.shtml';
	}
 
</SCRIPT>
</head>
<body class="bg">
<div class="content m_auto">
	<div class="content_l mt10">
    	<ul>
        	<li><a href="${basePath}scmInvocing/productInfo/forwardToProductInfo.shtml"><i class="nav_icon_b"></i><br>商品信息</a></li>
            <li><a href="${basePath}scmInvocing/countUnit/forwardToUnitInfo.shtml"><i class="nav_icon_b"></i><br>单位设置</a></li>
            <li><a href="${basePath}scmInvocing/supplier/forwardToSupply.shtml"><i class="nav_icon_a"></i><br>供应商信息</a></li>
            <li><a href="${basePath}scmInvocing/priceManager/forwardToList.shtml"><i class="nav_icon_f"></i><br>价格管理</a></li>
            <li  class="content_hover"><a href="${basePath}scmInvocing/scmPurOrder/findInvoPurOrder.shtml"><i class="nav_icon_b"></i><br>采购订单</a></li>
        <li><a href="${basePath}scmInvocing/scmPayForm/findInvoOrderPay.shtml"><i class="nav_icon_b"></i><br>付款申请</a></li>
        </ul>
    </div>
    <div class="content_r mt10">
    	<div class="p20">
            <div class="file_single_dl f14 fixed">
                <h1 class=""><font size="+1">采购订单清单</font></h1>
                <hr>
                <dl class="fixed" style="overflow:hidden"> 
                    <dd><label>采购订单编号：</label>${pkPurordId}</dd>
                </dl>
                <hr>
                <dl class="fixed" style="overflow:hidden">
                    <dd><label>制单人：</label>${applyName}</dd>
                    <dd><label>制单单位：</label>${brandName}</dd>
                    <dd>
                    <label> <font style="color:#F00">*</font>供应商：</label>
                     <div class="uboxstyle">
                           <select name="selectScmSupid" id="selectScmSupid" onchange="selectSupId(this)">
                            <option value="">请选择供应商</option>
                            <c:forEach items="${scmSupList}" var="scmSupply" varStatus="status">
			                        <option value="${scmSupply.pkSupId}" >${scmSupply.supName}</option>
                             </c:forEach>
                           </select>
                                    </div>
                    </dd>
                </dl>
                <hr>
            </div>
           <dl class="fixed order_dl">
                         	<!-- <dd><label><b>当前步骤：</b></label>总监审批</dd> -->
							<dd><label><b>处理历史：</b></label>
                        	<dd>
                            <table class="table" >
                                <tr>
                                    <th>时间</th>
                                    <th>处理人</th>
                                    <th>结果</th>
                                    <th>处理意见</th>
                                </tr>
                                 <c:forEach items="${hisWorkFlowList }" var="hisEntity" >
			                        <tr>
	                                    <td style="width:40%">${hisEntity.optTime }</td>
	                                    <td>${hisEntity.optName }</td>
	                                    <td>${hisEntity.result }</td>
	                                    <td title="${hisEntity.advice}">
	                                    <c:if test="${hisEntity.advice != null}">
	                                   	<c:choose>
	                                   		<c:when test="${hisEntity.advice.length()>80}">
	                                   			${hisEntity.advice.substring(0,80)}...
	                                  		 </c:when>
	                                   		<c:otherwise>
	                                    	${hisEntity.advice }
	                                   		</c:otherwise>
	                                    </c:choose>
	                                    </c:if>
	                                    </td> 
	                                </tr>
		                        </c:forEach>
                            </table>
                        </dd>
  
            	
            	</dl>
            <div class="mt10">
                <h1 class=""><font size="+1">采购商品目录</font></h1>
                <ul class="fixed" id="tab_conbox_a">
                    <li class="p10 h450">
        <form action="" id="supPrdForm">             
<div id="scrollTable" style="width:1100px">
    <table class="table">
        <col width="50px"></col>
        <col width="150px"></col>
        <col width="120px"></col>
        <col width="120px"></col>
        <col width="120px"></col>
        <col width="80px"></col>
        <col width="80px"></col>
        <col width="80px"></col>
        <col></col>
        <tbody>
           <tr>
              <th>序号</th>
              <th>商品编号</th>
              <th>商品名称</th>
              <th>商品分类</th>
              <th>规格</th>
              <th>单位</th>
              <th>协议单价(元)</th> 
              <th>采购数量</th> 
          </tr>
        </tbody>
    </table>
    <div style="height:377px !important">
    <table class="table" id="itemsTable">
        <col width="50px"></col>
        <col width="150px"></col>
        <col width="120px"></col>
        <col width="120px"></col>
        <col width="120px"></col>
        <col width="80px"></col>
        <col width="80px"></col>
        <col width="80px"></col>
        <col></col>
        <tbody>
           <c:forEach items="${listScmSupPrd}" var="scmSuppPrd" varStatus="status">
			                        <tr>
			                <td>${status.index+1}</td>
			                 <td>${scmSuppPrd.fkPrdId}</td>
			                <td title="${scmSuppPrd.prdName}"> 
			                	<c:if test="${fn:length(scmSuppPrd.prdName)>15}">${fn:substring(scmSuppPrd.prdName,0,15)}...
								</c:if>
							   　　   <c:if test="${fn:length(scmSuppPrd.prdName)<=15}">${scmSuppPrd.prdName}</c:if>
			                </td>
			                <td title="${scmSuppPrd.prdCateName}">
							<c:if test="${fn:length(scmSuppPrd.prdCateName)>13}">${fn:substring(scmSuppPrd.prdCateName,0,13)}...
								</c:if>
							   　　   <c:if test="${fn:length(scmSuppPrd.prdCateName)<=13}">${scmSuppPrd.prdCateName}</c:if>
							  </td>
			                <td>${scmSuppPrd.prdSpec}</td>
			                <td>${scmSuppPrd.unitName}</td> 
			                <td>${scmSuppPrd.agmPriceOne}</td> 
			                
			                <td>
			                 <c:choose>
		                  <c:when test="${null == scmSuppPrd.purCnt}">
		                     <input type="text" onkeyup="yazhengbigNum(this)" value="0" name="purCnt" id="purCnt${scmSuppPrd.fkPrdId}" class="iput_t w50"  />
		                   </c:when>
		                    <c:otherwise>
		                         <input type="text" onkeyup="yazhengbigNum(this)" value="${scmSuppPrd.purCnt }" name="purCnt" id="purCnt${scmSuppPrd.fkPrdId}" class="iput_t w50"  />
		                     </c:otherwise>
                           </c:choose>
			                </td>
			                <input type="hidden" name="agmPrice" id="agmPrice${scmSuppPrd.fkPrdId}" value="${scmSuppPrd.agmPriceOne}"/>
			                <input type="hidden" name="fkPrdIds" value="${scmSuppPrd.fkPrdId}"  value="${scmSuppPrd.fkPrdId}"/>
			                <input type="hidden" name="fkSupagmId" id="fksupAgmId${scmSuppPrd.fkPrdId}" value="${scmSuppPrd.fkSupagmId}"/>
			                </td> 
			            </tr>
           </c:forEach>
            
            
        </tbody>
    </table>
    </div>
    	
</div>
		
</form>
	
            	 
                        <div class="btm_btn m10">
                            <dl>
                            	 
                            	<!-- <dd><input class="btn" type="button" value="保存" onClick="saveSupRrd('save','1')"></dd> -->
                                <dd><input class="btn" type="button" value="提交" onClick="saveSupRrd('tijiao','2')"></dd>
                                <dd><input class="btn" type="button" value="返回" onClick="javascript:window.location.href='${basePath}scmInvocing/scmPurOrder/findInvoPurOrder.shtml'"></dd>
                               <dd><input class="btn" type="button" value="打印" ></dd>
                                
                            </dl>
                        </div>
                            
                          
                    </li>
                </ul>
            </div>
        </div>
    </div>
</div>
 
    
</div>
<div id="hide_loading">
	<div class="loading"></div>    
    <div class="loading_bg"></div>	
</div>
</body>
</html> 